﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Types/String.Extras</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
			<h4 class="menu-item"><a href="#String">String</a></h4>
			<div class="menu-item"><a href="#String:pad">pad</a></div>
			<div class="menu-item"><a href="#String:repeat">repeat</a></div>
			<div class="menu-item"><a href="#String:standardize">standardize</a></div>
			<div class="menu-item"><a href="#String:getTags">getTags</a></div>
			<div class="menu-item"><a href="#String:stripTags">stripTags</a></div>
			<div class="menu-item"><a href="#String:tidy">tidy</a></div>
			<div class="menu-item"><a href="#String:truncate">truncate</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="String"><a href="#String">Type: String</a></h1>

<p class="description">A collection of the String Object prototype methods.</p>

<h3>Tutorial/Demo</h3>

<ul>
<li><a href="http://www.clientcide.com/wiki/cnet-libraries/03-native/03-string.extras">Online Tutorial/Demo</a></li>
</ul>
<h3>See Also</h3>

<ul>
<li><a href="../../core/Types/String.html">String</a></li>
</ul>
<h2 id="String:pad"><a href="#String:pad">String Method: pad</a></h2>

<p class="description">Pads a string with the specified character(s) either before or after the current value.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">pad</span><span class="br0">(</span>length, string, direction<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>length - (<em>number</em>) the number of characters to pad.</li>
<li>string - (<em>string</em>) the string to use for padding; defaults to a space.</li>
<li>direction - (<em>string</em>) either "left", "right" or "both" (defaults to "right"); the side to add the padding.</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> tonyTheTigerSez = <span class="st0">"They're gr"</span>.<span class="me1">pad</span><span class="br0">(</span><span class="nu0">15</span>, <span class="st0">'r'</span><span class="br0">)</span> + <span class="st0">'eat!'</span>;
<span class="co1">//returns "They're grrrrrreat!"</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) a string with the specified character repeated the specified number of times either to the right or left of the current value.</li>
</ul>
<h2 id="String:repeat"><a href="#String:repeat">String Method: repeat</a></h2>

<p class="description">Repeats a string a specified number of times.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">repeat</span><span class="br0">(</span>times<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>times - (<em>number</em>) The number of times to repeat the string.</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> one = <span class="st0">"1"</span>;
<span class="kw2">var</span> eleventyOne = one.<span class="me1">repeat</span><span class="br0">(</span><span class="nu0">3</span><span class="br0">)</span>;
<span class="co1">//returns "111"</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) the string repeated the specified number of times.</li>
</ul>
<h2 id="String:standardize"><a href="#String:standardize">String Method: standardize</a></h2>

<p class="description">Removes non-ascii characters and converts them to their most appropriate ascii character.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">standardize</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> bjorkProper = <span class="st0">"BjÃƒÂ¶rk"</span>;
<span class="kw2">var</span> bjorkAscii = bjorkProper.<span class="me1">standardize</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//returns "Bjork"</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) a string without any non-ascii characters.</li>
</ul>
<h2 id="String:getTags"><a href="#String:getTags">String Method: getTags</a></h2>

<p class="description">Get all the HTML tags from a given string.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">getTags</span><span class="br0">(</span><span class="br0">[</span>tag, contents<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>tag - (<em>string</em>; optional) if defined, returns the tags of the specified type in an array. If not defined, returns all tags in an array.</li>
<li>contents - (<em>boolean</em>; optional) if <em>true</em>, you are returned an array of tag matches and their contents.</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> html = <span class="st0">"&lt;b&gt;This is a string with &lt;i&gt;html&lt;/i&gt; in it.&lt;/b&gt;"</span>
<span class="kw2">var</span> tags = html.<span class="me1">getTags</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//returns ["&lt;b&gt;", "&lt;i&gt;", "&lt;/i&gt;", "&lt;/b&gt;"]</span>
<span class="kw2">var</span> italics = html.<span class="me1">getTags</span><span class="br0">(</span><span class="st0">'i'</span><span class="br0">)</span>;
<span class="co1">//returns ["&lt;i&gt;", "&lt;/i&gt;"]</span>
<span class="kw2">var</span> italicsWithContent = html.<span class="me1">getTags</span><span class="br0">(</span><span class="st0">'i'</span>, <span class="kw2">true</span><span class="br0">)</span>;
<span class="co1">//returns ["&lt;i&gt;html&lt;/i&gt;"]</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>array</em>) An array of strings for each matched tag (important note: NOT <em>elements</em>, <em>strings</em>)</li>
</ul>
<h3>Note</h3>

<p>Currently, you cannot ask for all tags with their content. If you want the inner content of tags, you must specify the tag type.</p>

<h2 id="String:stripTags"><a href="#String:stripTags">String Method: stripTags</a></h2>

<p class="description">Remove all html tags from a string.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">stripTags</span><span class="br0">(</span><span class="br0">[</span>tag, contents<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>tag - (<em>string</em>; optional) if defined, returns the tags of the specified type in an array. If not defined, returns all tags in an array.</li>
<li>contents - (<em>boolean</em>; optional) if <em>true</em>, you are returned an array of tag matches and their contents.</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> html = <span class="st0">"&lt;b&gt;This is a string with &lt;i&gt;html&lt;/i&gt; in it.&lt;/b&gt;"</span>
<span class="kw2">var</span> noHtml = html.<span class="me1">stripTags</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//returns "This is a string with html in it."</span>
<span class="kw2">var</span> noItalics = html.<span class="me1">stripTags</span><span class="br0">(</span><span class="st0">'i'</span><span class="br0">)</span>;
<span class="co1">//returns "&lt;b&gt;This is a string with html in it.&lt;/b&gt;"</span>
<span class="kw2">var</span> noItalicsContent = html.<span class="me1">stripTags</span><span class="br0">(</span><span class="st0">'i'</span>, <span class="kw2">true</span><span class="br0">)</span>;
returns <span class="st0">"&lt;b&gt;This is a string with  in it.&lt;/b&gt;"</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) a string with the appropriate HTML stripped</li>
</ul>
<h2 id="String:tidy"><a href="#String:tidy">String Method: tidy</a></h2>

<p class="description">Replaces common special characters with their ASCII counterparts (smart quotes, elipse characters, stuff from MS Word, etc.).</p>

<h3>Syntax</h3>

<pre class="javascript"><span class="kw2">var</span> tidyString = stringWithBadChars.<span class="me1">tidy</span><span class="br0">(</span><span class="br0">)</span>;
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) the string with the non-ASCII characters replaced</li>
</ul>
<h2 id="String:truncate"><a href="#String:truncate">String Method: truncate</a></h2>

<p class="description">Truncates a string after the given number of characters.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">truncate</span><span class="br0">(</span>max, trail, atChar<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>max - (<em>number</em>) the maximum length of the string.</li>
<li>trail - (<em>string</em>, optional) the trail which will be appended to the string when it is truncated, defaults to <code>â€¦</code> when only the <code>max</code> argument is passed.</li>
<li>atChar - (<em>string</em>, optional) a string which be truncated after. For example before a space.</li>
</ol>
<h3>Returns</h3>

<ul>
<li>(<em>string</em>) the truncated string</li>
</ul>
<h3>Examples</h3>

<pre class="javascript"><span class="st0">'This is some random text'</span>.<span class="me1">truncate</span><span class="br0">(</span><span class="nu0">15</span><span class="br0">)</span>; <span class="co1">// This is some raÃ¢Â€Â¦</span>
<span class="st0">'This is some random text'</span>.<span class="me1">truncate</span><span class="br0">(</span><span class="nu0">15</span>, <span class="st0">'--'</span><span class="br0">)</span>; <span class="co1">// This is some ra--</span>
<span class="st0">'This is some random text'</span>.<span class="me1">truncate</span><span class="br0">(</span><span class="nu0">15</span>, <span class="st0">'Ã¢Â€Â¦'</span>, <span class="st0">' '</span><span class="br0">)</span>; <span class="co1">// This is someÃ¢Â€Â¦</span>
</pre>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
